package com.lixinxin.commoncomposeproject.screen

import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.spring
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.material.Card
import androidx.compose.material.Surface
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

/**
 *   author ： lixinxin
 *   time    ： 2021-11-26
 *   email：895330766@qq.com
 */


@Composable
fun ChatScreen() {


    var shakingTime by remember {
        mutableStateOf(0)
    }

    val shakingOffset = remember {
        Animatable(0f)
    }

    LaunchedEffect(key1 = shakingTime) {
        if (shakingTime != 0) {
            shakingOffset.animateTo(
                0f,
                animationSpec = spring(0.3f, 6000f),
                initialVelocity = -2000f
            )
        }

    }

    Surface(modifier = Modifier.fillMaxSize()) {

        Box(contentAlignment = Alignment.Center, modifier = Modifier.fillMaxSize()) {

            Card(
                modifier = Modifier
                    .width(100.dp)
                    .height(100.dp)
                    .offset(shakingOffset.value.dp, shakingOffset.value.dp)
                    .background(Color.Red)
                    .clickable {
                        shakingTime++
                    }

            ) {

            }

        }

    }


}